package com.weixin.engine.spring;

import com.weixin.engine.models.pojo.User;
import org.springframework.beans.factory.BeanFactory;

import java.beans.PropertyEditorSupport;

/**
 * BeanInfoDemo
 *
 * @author wangchunhui
 * @date 2022/8/23 14:59
 */
public class BeanInfoDemo {
    //    public static void main(String[] args) throws IntrospectionException {
//        BeanInfo beanInfo = Introspector.getBeanInfo(Uesr2.class, Object.class);
//        Stream.of(beanInfo.getPropertyDescriptors()).forEach(propertyDescriptor -> {
//            Class<?> propertyType = propertyDescriptor.getPropertyType();
//            String propertyName = propertyDescriptor.getName();
//            //为age字段/属性增加PropertyEditor
//            if ("age".equals(propertyName)) {
////                string -> integer
////                Integer.valueOf("")
//                propertyDescriptor.setPropertyEditorClass(StringToIntegerPropertyEditor.class);
//            }
//
//        });
//    }

    public static void main(String[] args) {

    }

    private static void lookupByType(BeanFactory beanFactory) {
        User user = beanFactory.getBean(User.class);
        System.out.println("实时查找：" + user);
    }

    static class StringToIntegerPropertyEditor extends PropertyEditorSupport {
        @Override
        public void setAsText(String text) throws java.lang.IllegalArgumentException {
            Integer value = Integer.valueOf(text);
            setValue(value);
        }
    }
}
